/*
 * Copyright (c) 2018. 
 * By:kaihangchen
 * E-mail:cmxds@hotmail.com
 */

package cn.cmxds.store.presenter.Impl;

import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import cn.cmxds.store.application.CustomApplcation;
import cn.cmxds.store.model.IGoodsResultModel;
import cn.cmxds.store.model.Impl.GoodsResultModel;
import cn.cmxds.store.presenter.IGoodsResultPresenter;
import cn.cmxds.store.view.IGoodsResultView;
public class GoodsResultPresenter implements IGoodsResultPresenter{
    private IGoodsResultView view;
    private IGoodsResultModel model;
    private GridView gridView;
    //数据源
//    private List<Goods> goodslists;
    public GoodsResultPresenter(IGoodsResultView view) {
        this.view = view;
        view.setPresenter(this);
    }

    @Override
    public void initData() {
        //获取控件
        gridView = view.getmActGoodsResultGv();
        //获取数据
        String datas = view.getDatas();
//        goodslists = new ArrayList<>();
        //查询数据
        queryDatasFromServer(datas);
        //设置item点击事件
        initEvent();
    }

    @Override
    public void setModel() {
        model=new GoodsResultModel();
    }

    /**
     * 从服务器上获取数据
     */
    private void queryDatasFromServer(final String datas) {

        view.showLoadingDialog("","数据加载中...", false);

        //根据商品的类别id查询显示数据



    }
    /**
     * 初始化点击事件
     */
    private void initEvent() {
        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                //将选中的活动保存到内存中
                CustomApplcation.putDatas("goods","datas");
                //跳转到商品详情页面
                GoodsResultPresenter.this.view.jumpActivity();
            }
        });
    }
}
